from tools.edge_selenium.edge_connection import edge_local_connection
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
import time

target_url = "https://www.wjx.cn/vm/hN60LBd.aspx#"
driver = edge_local_connection()


start_time = time.time()


for _ in range(1):

    try:
        driver.get(target_url)

        time.sleep(2)
        pageDiv = driver.find_element(By.ID, 'pageDiv')
        divContent = pageDiv.find_element(By.ID, 'divContent')
        divQuestion = divContent.find_element(By.ID, 'divQuestion')


        



        q1 = divQuestion.find_element(By.XPATH, "//div[@for='q1_1']").click()
        time.sleep(0.5)
        q2 = divQuestion.find_element(By.XPATH, "//div[@for='q2_1']").click()
        time.sleep(0.5)

        
        footer = divContent.find_element(By.CLASS_NAME, 'footer')
        divSubmit = footer.find_element(By.ID, 'divSubmit')
        SubmitBtnGroup = divSubmit.find_element(By.ID, 'SubmitBtnGroup')
        time.sleep(0.5)
        captchaOut = footer.find_element(By.ID, 'captchaOut')
        ctlNext = SubmitBtnGroup.find_element(By.ID, 'ctlNext').click()
        time.sleep(2)
        try:
            if '点击按钮开始智能验证'in captchaOut.text:
                layer_9 = footer.find_element(By.ID, 'captchaOut')\
                    .find_element(By.ID, 'captchaWrap').find_element(By.ID, "captcha")\
                        .find_element(By.ID, "SM_BTN_WRAPPER_1").click()
                time.sleep(3)
                try:
                    slider_element = driver.find_element(By.ID, "nc_1_n1z")
                    slider_container_width = 280
                    action_chains = ActionChains(driver)
                    action_chains.click_and_hold(slider_element).move_by_offset(slider_container_width, 0).release().perform()
                    time.sleep(2)
                except:
                    pass
        except:
            pass

        try:
            layer_10 = driver.find_element(By.CLASS_NAME, 'layui-layer.layui-layer-dialog')\
                .find_element(By.CLASS_NAME, 'layui-layer-btn.layui-layer-btn-')\
                    .find_element(By.TAG_NAME, 'a').click()
            time.sleep(2)
            layer_11 = footer.find_element(By.ID, 'captchaOut')\
                .find_element(By.ID, 'captchaWrap').find_element(By.ID, "captcha")\
                    .find_element(By.ID, "SM_BTN_WRAPPER_1").click()
            time.sleep(2)
        except:
            pass
    except:
        continue
        

    # 记录结束时间
end_time = time.time()
elapsed_time = end_time - start_time

print(f"程序运行时间: {elapsed_time} 秒")
